// pages/add_potential/add_potential.js
var util = require('../../utils/util');
var App = getApp();
var util_md5 = require('../../utils/md5.js');
var util_sha1 = require('../../utils/sha1.js');
var API_Key = "chaotingjianshen0012";

function jsonSort(jsonObj) {
    let arr = [];
    for (var key in jsonObj) {
        arr.push(key) 
    } 
    arr.sort(); 
    let str = ''; 
    for (var i in arr) {
        str += arr[i] + "=" + jsonObj[arr[i]] + "&"
    }
    return str.substr(0, str.length - 1)
}

function coding(data) {
    var detail = util_sha1.sha1(jsonSort(data))
    var datas_detail = util_md5.hexMD5(detail)
    var str = datas_detail;
    str = str.toUpperCase();
    return str;
}
Page({
    /**
     * 页面的初始数据
     */
    data: {
        isFold: true, //显示和隐藏
        type: '',
        name: '', //客户名
        card_name:'',//卡名称
        caller_phone: '', //客户手机号
        gender: '', //性别1男2女
        birthday: '', //出生年月日
        marital_status: '', //婚姻状况
        child_age: '', //有无小孩
        child: '0',
        house_address: '', //家庭住址
        company_address: '', //公司住址
        career_type: '', //职业类型
        vehicles: '', //交通工具
        come: '0', //曾经来过与否
        reason: '', //为什么选择来潮庭健身
        is_distance: '', //家或者公司哪个近
        health_club: '0', //之前在哪家健身俱乐部运动
        exercise_plan: '', //希望多久开始健身计划
        body_parts: '', //您最在意改变身体的哪个部位
        id:'',//修改id
        num:'',//卡的index
        bodys_parts: [{
            id: 1,
            name: '腰腹',
            checked: false
        }, {
            id: 2,
            name: '手臂',
            checked: false
        }, {
            id: 3,
            name: '腿',
            checked: false
        }], //您最在意改变身体的哪个部位
        exercise_type: '', //最喜欢的运动类型
        exercise_type_list: [{
            id: 1,
            name: '健身',
            checked: false
        }, {
            id: 2,
            name: '舞蹈',
            checked: false
        }, {
            id: 3,
            name: '瑜伽',
            checked: false
        }, {
            id: 4,
            name: '游泳',
            checked: false
        }, {
            id: 5,
            name: '其他',
            checked: false
        }],
        exercise_demand: '', //运动需求与期望效果
        exercise_demand_list: [{
            id: 1,
            name: '腰腹',
            checked: false
        }, {
            id: 2,
            name: '减重',
            checked: false
        }, {
            id: 3,
            name: '心肺功能提升',
            checked: false
        }, {
            id: 4,
            name: '塑性',
            checked: false
        }, {
            id: 5,
            name: '体态调整',
            checked: false
        }, {
            id: 6,
            name: '疼痛康复',
            checked: false
        }, {
            id: 7,
            name: '增加肌肉',
            checked: false
        }, {
            id: 8,
            name: '增加力量',
            checked: false
        }, {
            id: 9,
            name: '提高柔韧度',
            checked: false
        }, {
            id: 10,
            name: '放松压力',
            checked: false
        }],
        work_tire_degree: '', //工作疲劳程度
        is_injured: '', //是否受过伤
        unwell_part: '', //不舒服部位
        unwells_part: [{
            id: 1,
            name: '肩颈',
            checked: false
        }, {
            id: 2,
            name: '脊柱',
            checked: false
        }, {
            id: 3,
            name: '关节',
            checked: false
        }],
        fat_part: '', //脂肪囤积部位
        fat_part_list: [{
            id: 1,
            name: '肩颈',
            checked: false
        }, {
            id: 2,
            name: '脊柱',
            checked: false
        }, {
            id: 3,
            name: '臀部',
            checked: false
        }, {
            id: 4,
            name: '腿部',
            checked: false
        }],
        body_form: '', //身体形态
        dietary_law: '', //饮食规律
        dietary_habit: '', //饮食习惯
        sleep_quality: '', //睡眠品质
        source_types: ["新展", "轮排", "转介绍", "大众点评", "今日头条", "公众号", '电话咨询', '广告', '微信', '公开课', '开放日', '体验卡','美团'], //获客来源
        source_type: '', 
        rank: '', //客户级别
        workout_habit: '', //健康习惯
        client_tag: '', //客户标签
        clients_tag: [{
            id: 1,
            name: '消费力强',
            checked: false
        }, {
            id: 2,
            name: '消费力弱',
            checked: false
        }, {
            id: 3,
            name: '离家远',
            checked: false
        }, {
            id: 4,
            name: '距离近',
            checked: false
        }, {
            id: 5,
            name: '友善型',
            checked: false
        }, {
            id: 6,
            name: '刻薄型',
            checked: false
        }],
        intention_card_id: '', //意向卡种id
        card_list: [],
        array: [],
        index: 0,
        comment: '' //备注
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var This = this;
       
        var time = util.formatTime(new Date());
        var date_value = time.slice(0, 4) + "-" + time.slice(5, 7) + "-" + time.slice(8, 10)
        This.setData({
            birthday: date_value,
            type: options.type,
            id:options.id
        })
        console.log(options)
        if(This.data.type == 1){
            wx.setNavigationBarTitle({
                title: '修改潜客'
            })
        }else{
            wx.setNavigationBarTitle({
                title: '修改会员'
            })
        }
        
        This.loadin();
        setTimeout(function(){
            This.intention_list(); 
        },100)
    },
    //数据回填
    loadin:function(){
        var This = this;
        if(This.data.type == 1){
            console.log("666666666666")
            var pack = {
                openid: wx.getStorageSync('openid'),
                phone: wx.getStorageSync('phone'),
                store_id: wx.getStorageSync('store_id'),
                caller_id: This.data.id,
                token: API_Key,
            }
            var api = coding(pack);
            App._get("caller/callerExitView", {
                openid: wx.getStorageSync("openid"),
                store_id: wx.getStorageSync("store_id"),
                phone: wx.getStorageSync("phone"),
                signature: api,
                caller_id: This.data.id,
            },function(res){
                console.log(res)
                This.setData({
                    name: res.list.name,
                    caller_phone:res.list.phone,
                    gender: res.list.gender,
                    birthday: res.list.birthday,
                    card_name: res.list.card_name,
                    marital_status: res.list.marital_status,
                    child_age: res.list.child_age,
                    child: res.list.child,
                    house_address: res.list.house_address,
                    company_address: res.list.company_address,
                    career_type: res.list.career_type,
                    vehicles: res.list.vehicles,
                    come: res.list.come, //曾经来过与否
                    reason: res.list.reason, //为什么选择来潮庭健身
                    is_distance: res.list.is_distance, //家或者公司哪个近
                    health_club: res.list.health_club, //之前在哪家健身俱乐部运动 
                    club: res.list.club,
                    exercise_plan: res.list.exercise_plan, //希望多久开始健身计划
                    body_parts: res.list.body_parts, //您最在意改变身体的哪个部位
                    exercise_type: res.list.exercise_type, //最喜欢的运动类型
                    exercise_demand: res.list.exercise_demand, //运动需求与期望效果,
                    work_tire_degree: res.list.work_tire_degree, //工作疲劳程度
                    is_injured: res.list.is_injured, //是否受过伤
                    unwell_part: res.list.unwell_part, //不舒服部位
                    fat_part: res.list.fat_part, //脂肪囤积部位
                    body_form: res.list.body_form, //身体形态
                    dietary_law: res.list.dietary_law, //饮食规律
                    dietary_habit: res.list.dietary_habit, //饮食习惯
                    sleep_quality: res.list.sleep_quality, //睡眠品质
                    source_type: parseInt(res.list.source_type)-1, //获客来源
                    rank: res.list.rank, //客户级别
                    workout_habit: res.list.workout_habit, //健康习惯
                    client_tag: res.list.client_tag, //客户标签
                    intention_card_id: res.list.intention_card_id, //意向卡种id
                    comment: res.list.comment//备注
                })
                console.log(This.data.source_type)
                var body_parts_t = res.list.body_parts.split(",");//您最在意改变身体的哪个部位 分割字符串转换数组用于对应寻找ID
                console.log(body_parts_t)
                var bodys_parts_d = [];//您最在意改变身体的哪个部位 空数组用于替换和修改bodys_parts的change
                for (var j = 0; j < This.data.bodys_parts.length; j++) {
                    bodys_parts_d.push(This.data.bodys_parts[j])
                }
                for (var i = 0; i < body_parts_t.length; i++){
                    for (var k = 0; k < bodys_parts_d.length;k++){
                        if (body_parts_t[i] == bodys_parts_d[k].id){
                            bodys_parts_d[k].checked=true
                        }
                    }
                }
                This.setData({
                    bodys_parts: bodys_parts_d
                })
                var exercise_type_t = res.list.exercise_type.split(",");//最喜欢的运动类型 分割字符串转换数组用于对应寻找ID
                var exercise_type_d = [];//最喜欢的运动类型 空数组用于替换和修改bodys_parts的change
                for (var k = 0;k<This.data.exercise_type_list.length;k++){
                    exercise_type_d.push(This.data.exercise_type_list[k])
                }
                for (var i = 0; i < exercise_type_t.length;i++){
                    for (var j = 0; j < exercise_type_d.length;j++){
                        if (exercise_type_t[i] == exercise_type_d[j].id){
                            exercise_type_d[j].checked = true
                        }
                    }
                }
                This.setData({
                    exercise_type_list: exercise_type_d
                })
                var exercise_demand_t = res.list.exercise_demand.split(",");
                var exercise_demand_d = [];
                for (var k = 0; k < This.data.exercise_demand_list.length;k++){
                    exercise_demand_d.push(This.data.exercise_demand_list[k])
                }
                for (var i = 0; i < exercise_demand_t.length ; i++){
                    for (var j = 0; j < exercise_demand_d.length;j++){
                        if (exercise_demand_t[i] == exercise_demand_d[j].id){
                            exercise_demand_d[j].checked = true
                        }
                    }
                }
                This.setData({
                    exercise_demand_list: exercise_demand_d
                })
                var unwell_part_t = res.list.unwell_part.split(",");
                var unwell_part_d = [];
                for (var k = 0; k < This.data.unwells_part.length;k++){
                    unwell_part_d.push(This.data.unwells_part[k])
                }
                for (var i = 0; i < unwell_part_t.length;i++){
                    for (var j = 0; j < unwell_part_d.length;j++){
                        if (unwell_part_t[i] == unwell_part_d[j].id){
                            unwell_part_d[j].checked = true;
                        }
                    }
                }
                This.setData({
                    unwells_part: unwell_part_d
                })
                var client_tag_t = res.list.client_tag.split(",");
                var client_tag_d = [];
                for (var k = 0; k < This.data.clients_tag.length;k++){
                    client_tag_d.push(This.data.clients_tag[k])
                }
                for (var i = 0; i < client_tag_t.length;i++){
                    for (var j = 0; j < client_tag_d.length;j++){
                        if (client_tag_t[i] == client_tag_d[j].id){
                            client_tag_d[j].checked = true;
                        }
                    }
                }
                This.setData({
                    clients_tag: client_tag_d
                })
            })
        } else if (This.data.type == 2){
            console.log("888888888888")
            var pack = {
                openid: wx.getStorageSync('openid'),
                phone: wx.getStorageSync('phone'),
                store_id: wx.getStorageSync('store_id'),
                member_id: This.data.id,
                token: API_Key,
            }
            var api = coding(pack);
            App._get("member/memberViewData", {
                openid: wx.getStorageSync("openid"),
                store_id: wx.getStorageSync("store_id"),
                phone: wx.getStorageSync("phone"),
                signature: api,
                member_id: This.data.id,
            },function(res){
                console.log(res)
                This.setData({
                    name: res.list.name,
                    caller_phone: res.list.phone,
                    gender: res.list.gender,
                    birthday: res.list.birthday,
                    card_name: res.list.card_name,
                    marital_status: res.list.marital_status,
                    child_age: res.list.child_age,
                    child: res.list.child,
                    house_address: res.list.house_address,
                    company_address: res.list.company_address,
                    career_type: res.list.career_type,
                    vehicles: res.list.vehicles,
                    come: res.list.come, //曾经来过与否
                    reason: res.list.reason, //为什么选择来潮庭健身
                    is_distance: res.list.is_distance, //家或者公司哪个近
                    health_club: res.list.health_club, //之前在哪家健身俱乐部运动 
                    club: res.list.club,
                    exercise_plan: res.list.exercise_plan, //希望多久开始健身计划
                    body_parts: res.list.body_parts, //您最在意改变身体的哪个部位
                    exercise_type: res.list.exercise_type, //最喜欢的运动类型
                    exercise_demand: res.list.exercise_demand, //运动需求与期望效果,
                    work_tire_degree: res.list.work_tire_degree, //工作疲劳程度
                    is_injured: res.list.is_injured, //是否受过伤
                    unwell_part: res.list.unwell_part, //不舒服部位
                    fat_part: res.list.fat_part, //脂肪囤积部位
                    body_form: res.list.body_form, //身体形态
                    dietary_law: res.list.dietary_law, //饮食规律
                    dietary_habit: res.list.dietary_habit, //饮食习惯
                    sleep_quality: res.list.sleep_quality, //睡眠品质
                    source_type: parseInt(res.list.source_type) -1, //获客来源
                    rank: res.list.rank, //客户级别
                    workout_habit: res.list.workout_habit, //健康习惯
                    client_tag: res.list.client_tag, //客户标签
                    intention_card_id: res.list.member_card_id, //意向卡种id
                    comment: res.list.comment//备注
                })
                console.log(This.data.source_type)
                var body_parts_t = res.list.body_parts.split(",");//您最在意改变身体的哪个部位 分割字符串转换数组用于对应寻找ID
                console.log(body_parts_t)
                var bodys_parts_d = [];//您最在意改变身体的哪个部位 空数组用于替换和修改bodys_parts的change
                for (var j = 0; j < This.data.bodys_parts.length; j++) {
                    bodys_parts_d.push(This.data.bodys_parts[j])
                }
                for (var i = 0; i < body_parts_t.length; i++) {
                    for (var k = 0; k < bodys_parts_d.length; k++) {
                        if (body_parts_t[i] == bodys_parts_d[k].id) {
                            bodys_parts_d[k].checked = true
                        }
                    }
                }
                This.setData({
                    bodys_parts: bodys_parts_d
                })
                var exercise_type_t = res.list.exercise_type.split(",");//最喜欢的运动类型 分割字符串转换数组用于对应寻找ID
                var exercise_type_d = [];//最喜欢的运动类型 空数组用于替换和修改bodys_parts的change
                for (var k = 0; k < This.data.exercise_type_list.length; k++) {
                    exercise_type_d.push(This.data.exercise_type_list[k])
                }
                for (var i = 0; i < exercise_type_t.length; i++) {
                    for (var j = 0; j < exercise_type_d.length; j++) {
                        if (exercise_type_t[i] == exercise_type_d[j].id) {
                            exercise_type_d[j].checked = true
                        }
                    }
                }
                This.setData({
                    exercise_type_list: exercise_type_d
                })
                var exercise_demand_t = res.list.exercise_demand.split(",");
                var exercise_demand_d = [];
                for (var k = 0; k < This.data.exercise_demand_list.length; k++) {
                    exercise_demand_d.push(This.data.exercise_demand_list[k])
                }
                for (var i = 0; i < exercise_demand_t.length; i++) {
                    for (var j = 0; j < exercise_demand_d.length; j++) {
                        if (exercise_demand_t[i] == exercise_demand_d[j].id) {
                            exercise_demand_d[j].checked = true
                        }
                    }
                }
                This.setData({
                    exercise_demand_list: exercise_demand_d
                })
                var unwell_part_t = res.list.unwell_part.split(",");
                var unwell_part_d = [];
                for (var k = 0; k < This.data.unwells_part.length; k++) {
                    unwell_part_d.push(This.data.unwells_part[k])
                }
                for (var i = 0; i < unwell_part_t.length; i++) {
                    for (var j = 0; j < unwell_part_d.length; j++) {
                        if (unwell_part_t[i] == unwell_part_d[j].id) {
                            unwell_part_d[j].checked = true;
                        }
                    } 
                }
                This.setData({
                    unwells_part: unwell_part_d
                })
                var client_tag_t = res.list.client_tag.split(",");
                var client_tag_d = [];
                for (var k = 0; k < This.data.clients_tag.length; k++) {
                    client_tag_d.push(This.data.clients_tag[k])
                }
                for (var i = 0; i < client_tag_t.length; i++) {
                    for (var j = 0; j < client_tag_d.length; j++) {
                        if (client_tag_t[i] == client_tag_d[j].id) {
                            client_tag_d[j].checked = true;
                        }
                    }
                }
                This.setData({
                    clients_tag: client_tag_d
                })
            })
        } else{
            App.showError("数据错误请重试")
        }
        
    },
    btn() {
        var This = this;
        console.log(This.data.source_type)
        if (This.data.name == '') {
            App.showError('请填写客户姓名');
            return false;
        }
        if (This.data.caller_phone == '') {
            App.showError('请填写手机号');
            return false;
        }
        if (This.data.gender == '') {
            App.showError('请选择客户性别');
            return false;
        }
        if (This.data.birthday == '') {
            App.showError('请填写出生日期');
            return false;
        }
        if (This.data.source_type == 0){
            
        }else{
            if (This.data.source_type == '') {
                App.showError('请选择客户来源');
                return false;
            }
        }
        if (This.data.rank == '') {
            App.showError('请选择客户级别');
            return false;
        }
        if (This.data.workout_habit == '') {
            App.showError('请选择健身习惯');
            return false;
        }
        if (This.data.client_tag == '') {
            App.showError('请选择客户标签');
            return false;
        }
        if (This.data.intention_card_id == '') {
            App.showError('请选择意向卡种');
            return false;
        }
        var tr ={
            name:This.data.name,
            caller_phone: This.data.caller_phone,
            // card_name:This.data.card_name,
            gender: This.data.gender,
            birthday: This.data.birthday,
            marital_status: This.data.marital_status,
            child_age: This.data.child_age,
            child: This.data.child,
            house_address: This.data.house_address,
            company_address: This.data.company_address,
            career_type: This.data.career_type,
            vehicles: This.data.vehicles,
            come: This.data.come, //曾经来过与否
            reason: This.data.reason, //为什么选择来潮庭健身
            is_distance: This.data.is_distance, //家或者公司哪个近
            health_club: This.data.health_club, //之前在哪家健身俱乐部运动
            club: This.data.club,
            exercise_plan: This.data.exercise_plan, //希望多久开始健身计划
            body_parts: This.data.body_parts, //您最在意改变身体的哪个部位
            exercise_type: This.data.exercise_type, //最喜欢的运动类型
            exercise_demand: This.data.exercise_demand, //运动需求与期望效果,
            work_tire_degree: This.data.work_tire_degree, //工作疲劳程度
            is_injured: This.data.is_injured, //是否受过伤
            unwell_part: This.data.unwell_part, //不舒服部位
            fat_part: This.data.fat_part, //脂肪囤积部位
            body_form: This.data.body_form, //身体形态
            dietary_law: This.data.dietary_law, //饮食规律
            dietary_habit: This.data.dietary_habit, //饮食习惯
            sleep_quality: This.data.sleep_quality, //睡眠品质
            source_type: parseInt(This.data.source_type) +1, //获客来源
            rank: This.data.rank, //客户级别
            workout_habit: This.data.workout_habit, //健康习惯
            client_tag: This.data.client_tag, //客户标签
            intention_card_id: This.data.intention_card_id, //意向卡种id
            comment: This.data.comment//备注,
        }
        var data = {
            token: API_Key,
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            name: This.data.name,
            // signature: str,
            caller_id: This.data.id,
            data:tr
        }
        var data1 = {
            token: API_Key,
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            name: This.data.name,
            // signature: str,
            member_id: This.data.id,
            data: tr
        }
        console.log(data)
        var st = coding(data1);
        var str = coding(data);
        if (This.data.type == 1){
            console.log("6666")
            App._get('caller/callerExit', {
                signature: str,
                store_id: wx.getStorageSync('store_id'),
                openid: wx.getStorageSync('openid'),
                phone: wx.getStorageSync('phone'),
                caller_id: This.data.id,
                data: tr
            }, function (res) {

                if (res.status == 1) {
                    wx.showToast({
                        title: '修改成功',
                        duration: 2000
                    })
                    setTimeout(function(){
                        // wx.navigateTo({
                        //     url: '/pages/latent_maintenance/latent_maintenance?id=' + This.data.id + '&type=1',
                        // })
                        wx.navigateBack({
                            delta:1
                        })
                    },2000)
                } else {
                    wx.showToast({
                        title: res.error,
                        image: '../../image/icon_danger.png',
                        duration: 2000
                    })
                }
            })
        } else if (This.data.type == 2){
            console.log("9999999999")
            App._get('member/memberExit', {
                signature: st,
                store_id: wx.getStorageSync('store_id'),
                openid: wx.getStorageSync('openid'),
                phone: wx.getStorageSync('phone'),
                member_id: This.data.id,
                data: tr
            }, function (res) {

                if (res.status == 1) {
                    wx.showToast({
                        title: '修改成功',
                        duration: 2000
                    })
                    setTimeout(function () {
                        // wx.navigateTo({
                        //     url: '/pages/customer_information/customer information?id=' + This.data.id + '&type=2',
                        // })
                        wx.navigateBack({
                            delta: 1
                        })
                    }, 2000)
                } else {
                    wx.showToast({
                        title: res.error,
                        image: '../../image/icon_danger.png',
                        duration: 2000
                    })
                }
            })
        }
       
    },
    //控制隐藏和显示
    see_more() {
        var This = this;
        This.setData({
            isFold: !This.data.isFold
        });
        console.log(This.data.isFold)
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    //客户名
    name_input(e) {
        var This = this;
        This.setData({
            name: e.detail.value
        })
    },
    //客户手机号
    caller_phone_input(e) {
        var This = this;
        This.setData({
            caller_phone: e.detail.value
        })
    },
    //性别
    gender_btn(e) {
        var This = this;
        This.setData({
            gender: e.currentTarget.id
        })
    },
    //出生日期
    bindDateChange(e) {
        console.log(e)
        var This = this;
        This.setData({
            birthday: e.detail.value
        })
    },
    //婚姻情况
    marital_status_input(e) {
        var This = this;
        console.log(e)
        This.setData({
            marital_status: e.currentTarget.id
        })
    },
    //小孩几岁 有无小孩
    child_btn(e) {   
        var This = this;
        This.setData({
            child: e.currentTarget.id
        })
        if (This.data.child == 0) {
            This.setData({
                child_age: ''
            })
        }
    },
    child_input(e) {
        var This = this;
        This.setData({
            child_age: e.detail.value
        })
    },
    //家庭住址
    house_address_input(e) {
        var This = this;
        This.setData({
            house_address: e.detail.value
        })
    },
    //公司地址
    company_address_input(e) {
        var This = this;
        This.setData({
            company_address: e.detail.value
        })
    },
    //职业类型
    career_type_input(e) {
        var This = this;
        This.setData({
            career_type: e.detail.value
        })
    },
    // 交通工具 vehicles
    vehicles_input(e) {
        var This = this;
        This.setData({
            vehicles: e.detail.value
        })
    },
    //曾经来过与否
    come_btn(e) {
        var This = this
        This.setData({
            come: e.currentTarget.id
        })
    },
    //为什么选择来潮庭健身？
    reason_btn(e) {
        var This = this;
        This.setData({
            reason: e.currentTarget.id
        })
    },
    //家或者公司那个距离进
    is_distance_btn(e) {
        var This = this;
        This.setData({
            is_distance: e.currentTarget.id
        })
    },
    //之前在那家健身俱乐部运动
    health_club_btn(e) {
        var This = this;
        This.setData({
            health_club: e.currentTarget.id
        })
        if (This.data.health_club == 0) {
            This.setData({
                club: ''
            })
        }
    },
    health_club_input(e) {
        var This = this;
        This.setData({
            club: e.detail.value
        })
    },
    //希望多久开始健身计划？
    exercise_plan_btn(e) {
        var This = this;
        This.setData({
            exercise_plan: e.currentTarget.id
        })
    },
    //你最在意改变的身体的部位？
    body_parts_btn(e) {
        var This = this;
        var bodys_parts = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.bodys_parts[index];
        item.checked = !item.checked;
        This.setData({
            bodys_parts: This.data.bodys_parts,
        });
        for (var i = 0; i < This.data.bodys_parts.length; i++) {
            if (This.data.bodys_parts[i].checked) {
                bodys_parts.push(This.data.bodys_parts[i].id)
            }
        }
        This.setData({
            body_parts: bodys_parts.join(',')
        })
        console.log(This.data.body_parts)

    },
    //最喜欢的运动类型？
    exercise_type_btn(e) {
        var This = this;
        var exercise_type = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.exercise_type_list[index];
        item.checked = !item.checked;
        This.setData({
            exercise_type_list: This.data.exercise_type_list,
        });
        for (var i = 0; i < This.data.exercise_type_list.length; i++) {
            if (This.data.exercise_type_list[i].checked) {
                exercise_type.push(This.data.exercise_type_list[i].id)
            }
        }
        This.setData({
            exercise_type: exercise_type.join(',')
        })
        console.log(This.data.exercise_type)
    },
    //运动需求与期望效果
    exercise_demand_btn(e) {
        var This = this;
        var exercise_demand = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.exercise_demand_list[index];
        item.checked = !item.checked;
        This.setData({
            exercise_demand_list: This.data.exercise_demand_list,
        });
        for (var i = 0; i < This.data.exercise_demand_list.length; i++) {
            if (This.data.exercise_demand_list[i].checked) {
                exercise_demand.push(This.data.exercise_demand_list[i].id)
            }
        }
        This.setData({
            exercise_demand: exercise_demand.join(',')
        })
        console.log(This.data.exercise_demand)
    },
    //工作疲劳程度
    unwell_part_btn(e) {
        var This = this;
        var unwells_part = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.unwells_part[index];
        item.checked = !item.checked;
        This.setData({
            unwells_part: This.data.unwells_part,
        });
        for (var i = 0; i < This.data.unwells_part.length; i++) {
            if (This.data.unwells_part[i].checked) {
                unwells_part.push(This.data.unwells_part[i].id)
            }
        }
        This.setData({
            unwell_part: unwells_part.join(',')
        })
        console.log(This.data.unwell_part)
    },
    //是否受过伤
    is_injured_btn(e) {
        var This = this;
        This.setData({
            is_injured: e.currentTarget.id
        })
    },
    //不舒服部位
    work_tire_degree_btn(e) {
        var This = this;
        This.setData({
            work_tire_degree: e.currentTarget.id
        })
    },
    //脂肪囤积部位
    fat_part_btn(e) {
        var This = this;
        This.setData({
            fat_part: e.currentTarget.id
        })
        console.log(This.data.fat_part)
    },
    //身体形态
    body_form_btn(e) {
        var This = this;
        This.setData({
            body_form: e.currentTarget.id
        })
    },
    //饮食规律
    dietary_law_btn(e) {
        var This = this;
        This.setData({
            dietary_law: e.currentTarget.id
        })
    },
    //饮食习惯
    dietary_habit_btn(e) {
        var This = this;
        This.setData({
            dietary_habit: e.currentTarget.id
        })
    },
    //睡眠质量
    sleep_quality_btn(e) {
        var This = this;
        This.setData({
            sleep_quality: e.currentTarget.id
        })
    },
    //获客来源
    source_type_change(e) {
        var This = this; 
        console.log(e.detail.value)
        var id = e.detail.value
        This.setData({
            source_type: e.detail.value,
            // source_type: parseInt(id)
        })
        console.log(This.data.source_type)
    },
    //客户级别
    rank_btn(e) {
        var This = this;
        This.setData({
            rank: e.currentTarget.id
        })
    },

    //健身习惯
    workout_habit_btn(e) {
        var This = this;
        This.setData({
            workout_habit: e.currentTarget.id
        })
    },

    //客户标签
    client_tag_btn(e) {
        var This = this;
        var clients_tag = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.clients_tag[index];
        item.checked = !item.checked;
        This.setData({
            clients_tag: This.data.clients_tag,
        });
        for (var i = 0; i < This.data.clients_tag.length; i++) {
            if (This.data.clients_tag[i].checked) {
                clients_tag.push(This.data.clients_tag[i].id)
            }
        }
        This.setData({
            client_tag: clients_tag.join(',')
        })
        console.log(This.data.client_tag)
    },
    //卡片种类获取
    intention_list(e) {
        var This = this;
        App._get('Caller/intention_list', {
            phone: wx.getStorageSync('phone'),
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid')
        }, function (res) {
            var cards = []
            for (var i = 0; i < res.list.length; i++) {
                cards.push(res.list[i].name)
            }
            console.log(cards)
            for(var j=0;j<cards.length;j++){
                console.log(j)
                console.log(This.data.card_name)
                if (cards[j] == This.data.card_name){
                    console.log(j)
                    console.log(This.data.card_name)
                    This.setData({
                        num:j
                    })
                }
            }
            This.setData({
                array: res.list,
                card_list: cards,
                intention_card_id: res.list[0].id
            })
        })
    },
    cards_change(e) {
        var This = this;
        console.log(e)
        This.setData({
            num: e.detail.value,
            intention_card_id: This.data.array[e.detail.value].id
        })
        console.log(This.data.intention_card_id)
    },
    comment_input(e) {
        var This = this;
        This.setData({
            comment: e.detail.value
        })
        console.log(This.data.comment)
    },
    //intention_card_id
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})